<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客管理</title>

    <link rel="stylesheet" href="../../static/lib/editormd/css/editormd.min.css"
          th:href="@{/lib/editormd/css/editormd.min.css}">
    <link href="https://cdn.bootcss.com/semantic-ui/2.4.1/semantic.min.css" rel="stylesheet">
    <link rel="stylesheet" href="../../static/css/main.css" th:href="@{/css/main.css}">
</head>
<body>
<!--顶部导航-->
<header th:replace="admin/_fragments::header(0)" class="ui inverted attached segment m-shadow-small">
    <div class="ui container">
        <nav class="ui inverted secondary stackable menu">
            <h2 class="ui header teal item m-header-logo">管理后台</h2>
            <a href="#" class="active m-header-item m-hide-on-mobile item"><i class="small home icon"></i> 博客</a>
            <a href="#" class="m-header-item m-hide-on-mobile item"><i class="small idea icon"></i> 分类</a>
            <a href="#" class="m-header-item m-hide-on-mobile item"><i class="small tag icon"></i> 标签</a>
            <div class="right menu m-header-item m-hide-on-mobile">
                <div class="ui dropdown item">
                    <div class="text">
                        <img src="https://picsum.photos/50" alt="" class="ui avatar image"> Misty
                    </div>
                    <i class="dropdown icon"></i>
                    <div class="menu">
                        <a href="#" class="item">注销</a>
                    </div>
                </div>
            </div>
        </nav>
    </div>

    <a href="#" class="ui black icon button m-header-toggle-icon m-show-on-mobile toggle">
        <i class="sidebar icon"></i>
    </a>
</header>

<!--二级导航-->
<div class="ui attached pointing menu">
    <div class="ui container">
        <div class="right menu">
            <a href="javascript:void(0)" class="active item">发布</a>
            <a href="#" class="item" th:href="@{/admin/blogs}">列表</a>
        </div>
    </div>
</div>

<!--中间内容-->
<section class="m-article-container m-padding-tb-large">
    <div class="ui container">
        <div class="ui container">
            <form id="contentForm" action="#" method="post" class="ui form" th:action="@{/admin/blogs}"
                  th:object="${article}">
                <input type="hidden" name="id" th:value="*{id}" readonly>
                <input type="hidden" name="published" readonly>
                <div class="required field">
                    <div class="ui left labeled input">
                        <div class="ui selection compact dropdown teal basic label">
                            <input type="hidden" value="原创1" name="flag" th:value="*{flag} ?: '原创'">
                            <i class="dropdown icon"></i>
                            <div class="text">原创</div>
                            <div class="menu">
                                <div class="item" data-value="原创">原创</div>
                                <div class="item" data-value="转载">转载</div>
                                <div class="item" data-value="翻译">翻译</div>
                            </div>
                        </div>
                        <input type="text" name="title" placeholder="标题" th:value="*{title}">
                    </div>
                </div>
                <div class="required field">
                    <div id="md-content" style="z-index: 1 !important;">
                        <textarea style="display: none;" placeholder="文章内容" name="content"
                                  th:text="*{content}"></textarea>
                    </div>
                </div>
                <div class="two fields">
                    <div class="required field">
                        <div class="ui left labeled action input">
                            <label class="ui compact teal basic label">分类</label>
                            <div class="ui fluid selection dropdown">
                                <input type="hidden" name="category.id" th:value="*{category?.id}">
                                <i class="dropdown icon"></i>
                                <div class="default text">分类</div>
                                <div class="menu">
                                    <div class="item" data-value="1" th:each="cate : ${categories}"
                                         th:data-value="${cate.id}" th:text="${cate.name}">错误日志
                                    </div>
                                    <!--/*-->
                                    <div class="item" data-value="2">开发者手册</div>
                                    <!--*/-->
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="field">
                        <div class="ui left labeled action input">
                            <label class="ui compact teal basic label">标签</label>
                            <div id="tagDropdown" class="ui fluid multiple search selection dropdown">
                                <input type="hidden" name="tagIds" th:value="*{tagIds}">
                                <i class="dropdown icon"></i>
                                <div class="default text">标签</div>
                                <div class="menu">
                                    <div class="item" data-value="1" th:each="tag : ${tags}"
                                         th:data-value="${tag.id}" th:text="${tag.name}">java
                                    </div>
                                    <!--/*-->
                                    <div class="item" data-value="2">javascript</div>
                                    <!--*/-->
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="required field">
                    <div class="ui left labeled input">
                        <label class="ui teal basic label">首图</label>
                        <input type="text" name="firstPicture" placeholder="首图引用地址" th:value="*{firstPicture}">
                    </div>
                </div>

                <div class="required field">
                    <textarea name="description" th:text="*{description}"></textarea>
                </div>

                <div class="inline fields">
                    <div class="field">
                        <div class="ui checkbox">
                            <input type="checkbox" id="recommend" name="recommend" class="hidden"
                                   th:checked="*{recommend}">
                            <label for="recommend">推荐</label>
                        </div>
                    </div>

                    <div class="field">
                        <div class="ui checkbox">
                            <input type="checkbox" id="shareStatement" name="shareStatement" class="hidden"
                                   th:checked="*{shareStatement}">
                            <label for="shareStatement">转载声明</label>
                        </div>
                    </div>

                    <div class="field">
                        <div class="ui checkbox">
                            <input type="checkbox" id="appreciation" name="appreciation" class="hidden"
                                   th:checked="*{appreciation}">
                            <label for="appreciation">赞赏</label>
                        </div>
                    </div>

                    <div class="field">
                        <div class="ui checkbox">
                            <input type="checkbox" id="commentable" name="commentable" class="hidden"
                                   th:checked="*{commentable}">
                            <label for="commentable">评论</label>
                        </div>
                    </div>
                </div>

                <div class="ui error message"></div>

                <div class="ui right aligned container">
                    <button type="button" class="ui button" onclick="window.history.go(-1)">返回</button>
                    <button type="button" id="saveBtn" class="ui secondary button">保存</button>
                    <button type="button" id="publishBtn" class="ui teal button">发布</button>
                </div>
            </form>
        </div>
    </div>
</section>

<!--footer-->
<footer th:replace="admin/_fragments::footer" class="ui vertical inverted segment m-footer">
    <div class="ui container center aligned">
        <div class="ui stackable grid divided inverted">
            <!--二维码-->
            <div class="three wide column">
                <div class="ui inverted link list">
                    <div class="item">
                        <img src="https://via.placeholder.com/110?text=WeChat" class="ui rounded image" alt="">
                    </div>
                </div>
            </div>
            <!--二维码-->

            <!--最新博客-->
            <div class="three wide column">
                <h4 class="ui inverted header m-text-thin m-text-spacing">最新博客</h4>
                <div class="ui inverted link list">
                    <a href="#" class="item">用户故事 (User Story)</a>
                    <a href="#" class="item">用户故事 (User Story)</a>
                    <a href="#" class="item">用户故事 (User Story)</a>
                </div>
            </div>
            <!--最新博客-->

            <!--联系我-->
            <div class="three wide column">
                <h4 class="ui inverted header m-text-thin m-text-spacing">联系我</h4>
                <div class="ui inverted link list">
                    <a href="#" class="item">Email:</a>
                    <a href="#" class="item">QQ:</a>
                </div>
            </div>
            <!--联系我-->

            <!--关于-->
            <div class="seven wide column">
                <h4 class="ui inverted header m-text-thin m-text-spacing">关于</h4>
                <p class="m-text-thin m-text-spacing m-opacity-80">這是我的個人博客</p>
            </div>
            <!--关于-->

        </div>
        <div class="ui inverted section divider"></div>
        <p class="m-text-thin m-text-spacing m-opacity-60">by Misty</p>
    </div>
</footer>

<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/semantic-ui/2.4.1/semantic.min.js"></script>
<script src="../../static/lib/editormd/editormd.min.js" th:src="@{/lib/editormd/editormd.js}"></script>

<script th:inline="javascript">
    const editorMdPath = /*[[@{/lib/editormd/lib/}]]*/ "../../static/lib/editormd/lib/";
</script>

<script>
    $("header > a.toggle.button").click(function () {
        $(".m-header-item").toggleClass('m-hide-on-mobile');
        return false
    });
    $(".ui.dropdown").dropdown({
        on: 'hover',
    });
    $(".ui.form").form({
        fields: {
            title: {
                identifier: "title",
                rules: [{
                    type: "empty",
                    prompt: "请输入博客标题"
                }]
            },
            content: {
                identifier: "content",
                rules: [{
                    type: "empty",
                    prompt: "请输入文章内容"
                }]
            },
            categoryId: {
                identifier: "categoryId",
                rules: [{
                    type: "empty",
                    prompt: "请选择博客分类"
                }]
            },
            firstPicture: {
                identifier: "firstPicture",
                rules: [{
                    type: "empty",
                    prompt: "请输入博客首图"
                }]
            },
            description: {
                identifier: "description",
                rules: [{
                    type: "empty",
                    prompt: "请输入文章描述"
                }]
            }
        }
    });

    $("#saveBtn").click(function () {
        $("[name='published']").val(false);
        $("#contentForm").submit();
    });

    $("#publishBtn").click(function () {
        $("[name='published']").val(true);
        $("#contentForm").submit();
    });

    var contentEditor;
    $(function () {
        contentEditor = editormd({
            id: "md-content",
            width: "100%",
            height: 640,
            syncScrolling: "single",
            path: editorMdPath
        })
    });
</script>
</body>
</html>